function Login_Code() {
	var headimg="img/head_user.png";
	if(User)
	{
		headimg=User.HeadImg;
	}
	var buffer = new StringBuffer();
	buffer.append('<div class="login">');
	buffer.append('<div class="loginimg"><img id="headimg" src="'+headimg+'"/></div>');
	buffer.append('<div class="logintext border-bottom"><div class="tip">账号</div><div class="text"><input type="tel" maxlength="11" id="username" placeholder="输入手机号" onkeyup="Set_HeadImg(this)" /></div></div>');
	buffer.append('<div class="logintext border-bottom"><div class="tip">密码</div><div class="text"><input type="password" id="userpwd" placeholder="输入密码" /></div></div>');
	buffer.append('<div class="logintext" style="text-align: right;"><div class="losspwd"><a id="findback_pwd">忘记密码</a></div></div>');
	buffer.append('<div class="logintext" style="height:60px;"><button id="login" class="button blue">立即登录</button></div>');
	buffer.append('<div class="logintext" style="text-align: right;"><a id="regist_link">注册新用户</a></div>');
	buffer.append('</div>');
	return buffer.toString();
};

function Set_HeadImg(o){
	if(User){
		if(o.value.Trim()==User.UserName)
		{
			get("headimg").src=User.HeadImg;
		}else
		{
			get("headimg").src="img/head_user.png";
		}
	}
};

function FindPwd_Code()
{
	var default_mobile="";
	if($("#username").val().Trim().length==11)
	{
		default_mobile=$("#username").val().Trim();
	}
	var buffer = new StringBuffer();
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle" style="width:20%;"><div class="cname">手机号</div></div><div class="ctext" style="width:50%;"><input id="txt_mobile"  type="tel" placeholder="填写手机号" value="'+default_mobile+'"/></div><div id="sendsms" class="sendsms">发送验证码</div><div id="leavetime" class="leavetime">60s</div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle" style="width:20%;"><div class="cname">验证码</div></div><div class="ctext" style="width:50%;"><input id="txt_smscode" type="tel" placeholder="填写验证码" value="" /></div></div>');
	return buffer.toString();
};

function Init_FindPwd(){
	OpenWindow2(1,"找回密码","找回",function(){
		var data={};
		var mobile=$("#txt_mobile").val().Trim();
		data.act="FindBack_Pwd";
      	data.mobile=mobile;
      	data.smscode=$("#txt_smscode").val().Trim();
      	if(mobile=="")
	    {
	        plus.nativeUI.toast("手机号码不能为空");
	        return;
	    }
		if(mobile.length!=11)
	    {
	        plus.nativeUI.toast("手机号码必须为11位数字");
	        return;
	    }
      	if(data.smscode=="")
      	{
      		plus.nativeUI.toast("请输入验证码");
      		return;
      	}
	    data.sign=GetSign(data.act);
	    plus.nativeUI.showWaiting( "正在找回..." );
	    mui.getJSON(login_domain, data, function(json){
	    	plus.nativeUI.closeWaiting();
	    	if(json.state)
	    	{
	    		plus.nativeUI.alert(json.msg);
	    	}else
	    	{
	    		plus.nativeUI.toast(json.msg);
	    	}
	    });
	});
	$("#contentlist1").html(FindPwd_Code());
	get("sendsms").addEventListener("tap",function(){
		var mobile=$("#txt_mobile").val().Trim();
		if(mobile=="")
	    {
	        plus.nativeUI.toast("手机号码不能为空");
	        return;
	    }
		if(mobile.length!=11)
	    {
	        plus.nativeUI.toast("手机号码必须为11位数字");
	        return;
	    }
	    plus.nativeUI.showWaiting( "正在发送..." );
	    var data={};
      	data.act="Send_SmsCode";
      	data.mobile=mobile;
      	data.sign=GetSign(data.act);
	    mui.getJSON(login_domain, data, function(json){
	    	plus.nativeUI.closeWaiting();
	    	plus.nativeUI.toast(json.msg);
	    	if(json.state)
	    	{
	    		$("#sendsms").hide();
	    		$("#leavetime").show();
	    		Count_Down();
	    	}
	    });
	});
};

var countdown=60;
function Count_Down(){
	cd = setTimeout(function(){
		countdown--;
		if(countdown==0)
		{
			countdown=60;
			$("#sendsms").show();
	    	$("#leavetime").hide();
			clearTimeout(cd);
		}else
		{
			$("#leavetime").html(countdown+"s");
			Count_Down();
		}
		
	},1000);
};

function Main(){
	var buffer = new StringBuffer();
	buffer.append('<div id="iframe">');
		buffer.append('<div class="title"><div class="back"></div><div class="name">消息</div><div class="tool"></div></div>');
		buffer.append('<div class="sign border-bottom">');
			buffer.append('<div class="sign_state"><div id="sign_quan" class="sign_quan">未签到<br><font>--</font></div></div>');
			buffer.append('<div class="sign_time"><div class="time1">上班时间</div><div class="time2">'+Get_SignTime(User.SignRule)+'</div></div>');
			buffer.append('<div class="sign_checkin"><div class="shadow"></div><img id="checkin" src="img/sign.png"/></div>');
			buffer.append('<div class="sign_position"><div class="pos"><img src="img/position.jpg"/></div><div id="address" class="address"></div><div class="reflash"><!--<img src="img/reflash.jpg"/>--></div></div>');
		buffer.append('</div>');
		buffer.append('<div id="content" class="content" style="height:'+(sheight-245)+'px;">');
			buffer.append('<ul id="often5" ids="" rids="" pids="" tableid="5" >');
				buffer.append('<li tablename=""><div class="line border-bottom"><div class="icon"><img src="img/notice.png"></div><div class="name">公告</div><div class="detail">这里是您的所有公告</div><div class="date"></div></div></li>');
			buffer.append('</ul>');
		buffer.append('</div>');
	buffer.append('</div>');
	buffer.append('<div class="footer border-top">');
		buffer.append('<ul>');
			buffer.append('<li id="nav_oa"><div class="icon"><img src="img/qixins.png" /></div><div class="name" style="color:#1795cf;">消息</div><span id="noticecount" class="hidden"></span></li>');
			buffer.append('<li id="nav_crm"><div class="icon"><img src="img/mate.png" /></div><div class="name">同事</div></li>');
			buffer.append('<li id="nav_app"><div class="icon"><img src="img/app.png" /></div><div class="name">应用</div></li>');
			buffer.append('<li id="nav_find"><div class="icon"><img src="img/find.png" /></div><div class="name">发现</div><span id="findcount" class="fcircle hidden" circlehead=""></span></li>');
			buffer.append('<li id="nav_my"><div class="icon"><img src="img/me.png" /></div><div class="name">我的</div></li>');
		buffer.append('</ul>');
	buffer.append('</div>');
	buffer.append('<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true" style="z-index:999">'); 
    buffer.append('<div class="pswp__bg"></div>');
    buffer.append('<div class="pswp__scroll-wrap">');
        buffer.append('<div class="pswp__container">');
            buffer.append('<div class="pswp__item"></div>');
            buffer.append('<div class="pswp__item"></div>');
            buffer.append('<div class="pswp__item"></div>');
        buffer.append('</div>');
        buffer.append('<div class="pswp__ui pswp__ui--hidden">');
            buffer.append('<div class="pswp__top-bar">');
                buffer.append('<div class="pswp__counter"></div>');
                buffer.append('<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>');
                buffer.append('<button class="pswp__button pswp__button--share" title="Share"></button>');
                buffer.append('<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>');
                buffer.append('<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>');
                buffer.append('<div class="pswp__preloader">');
                    buffer.append('<div class="pswp__preloader__icn">');
                      buffer.append('<div class="pswp__preloader__cut">');
                        buffer.append('<div class="pswp__preloader__donut"></div>');
                      buffer.append('</div>');
                    buffer.append('</div>');
                buffer.append('</div>');
            buffer.append('</div>');
            buffer.append('<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">');
                buffer.append('<div class="pswp__share-tooltip"></div> ');
            buffer.append('</div>');
            buffer.append('<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button>');
            buffer.append('<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button>');
            buffer.append('<div class="pswp__caption"><div class="pswp__caption__center"></div></div>');
          buffer.append('</div>');
        buffer.append('</div>');
		buffer.append('</div>');
		buffer.append('<div id="pos_map"></div>');
	return buffer.toString();
};

function Init_Main()
{
	$("body").html(Main());
	pos_map=new plus.maps.Map("pos_map");
	Init_BottomTool();
	CrmOpenDB();
	
	setTimeout(function(){ //如果不加settimeout，则如果登陆页有软键盘，会给首页留下空白
	    reheight(245);
	},300);
	//让图标显示漂亮一些
		var left= 0;
		if(swidth==320){
			left=5;
		}
		if(swidth==360){
			left=1;
		}
		if(swidth==375){
			left=0;
		}
		$("head").append("<style>.content .often{padding-left:"+left+"px;padding-right:"+left+"px;}"); 
	
	var net=plus.networkinfo.getCurrentType();
	if(net==3){ //如果是wifi网络,静默更新
		plus.runtime.getProperty(plus.runtime.appid, function(inf) {
			var data = {};
			data.act = "Get_Version";
			data.sign=GetSign(data.act);
			mui.getJSON(index_domain, data, function(json) {
				if(plus.device.vendor=="Apple" && json.data.IOSVersion!=inf.version)
				{
					AutoDownWgt();
				}
				if(plus.device.vendor!="Apple" && json.data.AndroidVersion!=inf.version)
				{
					plus.nativeUI.confirm(json.data.Context.split("<br>").join("\n"), function(event){
								if(event.index==1)
								{
									DownWgt("qiyedaishu.apk");
								}
							},"有可升级的版本，是否升级？", ["取消","确认"]);
				}
			});
		});
	}
};

function Set_SignRule(){
	OpenWindow(1,"打卡设置列表","<font>+</font>",function(){
									OpenWindow(2,"新增打卡规则","保存",function(){
										Save_SignRule();
									});
									$("#contentlist2").html(SignRuleAdd_Code(0,0,"",0));
									Init_SignRuleAdd();
								});
								Receive_SignRule(1);
};

function Login_Update(){
	var client = plus.push.getClientInfo();
	var data={};
      			data.act="Login_Update";
      			data.userid=userid;
      			data.comid=comid;
      			data.source=source;
      			data.version=version;
      			data.clientid=client.clientid;
      			data.token=client.token;
      			data.editions=editions;
      			data.sign=GetSign(data.act);
      			mui.getJSON(login_domain, data, function(json){
      			});
};
